<?php
	header("content-type:text/html;charset=utf-8");
	abstract  class Check{
		abstract function checkUsername($str);
		abstract function checkPassword($str);
		abstract function checkEmail($str);
	}
	//$a = new Check();抽象类不允许实例化对象
	
	class CheckDetail extends Check{
		/*
		 * 统计这些检查方法被使用的次数
		 * $count_username
		 * $count_password
		 * $count_email
		 */
		static $count_username = 0;
		static $count_password = 0;
		static $count_email = 0;
		
		//字母开头，由数字字母下划线组成，5~30位
		function checkUsername($str){
			self::$count_username++;
			if(preg_match("/^[a-z]\w{4,29}$/i", $str)){
				//echo $str." checkUsername 合法！<br>";
				return true;
			}else{
				echo $str." checkUsername 不合法！<br>";
				return false;
			}
		}
		
		//字符组成，6位以上
		function checkPassword($str){
			self::$count_password++;
			if(preg_match("/^(.){6,}/i", $str)){
				//echo $str," checkPassword 合法!<br>";
				return true;
			}else{
				echo $str," checkPassword 不合法!<br>";
				return false;
			}
		}
		
		//任意的 .... @ ... 点 com 点 cn
		function checkEmail($str){
			self::$count_email++;
			if(preg_match("/^\w+@\w+(\.\w+)+$/", $str)){
				echo $str," checkEmail 合法！<br>";
			}else{
				echo $str," checkEmail 不合法！<br>";
			}
		}
		
		function __call($fname,$fvalue){
			echo "call...<br>";
			
			if(strtolower($fname) == 'username'){
				$this->checkUsername($fvalue);
			}elseif(strtolower($fname) == 'password'){
				$this->checkPassword($fvalue);
			}elseif(strtolower($fname) == 'email'){
				$this->checkEmail($fvalue);
			}else{
				echo $fname," 非法操作！<br>";
			}
		}
	}
	//CheckDetail::$count_email = 0;
	
	/*
	$a = new CheckDetail();
	$a->checkUsername("1234");
	$a->checkIp("127.0.0.1");
	$a->__call("Username","e1234");
	
	$b = new CheckDetail();
	$b->checkUsername("56s3");
	
	echo CheckDetail::$count_username;
	*/
	
?>